<?php
require $_SERVER['DOCUMENT_ROOT'].'/../_core/common.php';

//权限验证
if( Role::init() == false ){
	exit('没有权限');
}

$db = new DB('news');

$id_string = '';
for( $i=0; $i<count($_POST['id']); $i++ ){
	$id = isset($_POST['id'][$i]) ? intval($_POST['id'][$i]) : 0;
	$orders = isset($_POST['orders'][$i]) ? intval($_POST['orders'][$i]) : 0;
	$title = isset($_POST['title'][$i]) ? h($_POST['title'][$i]) : '';
	$url = isset($_POST['url'][$i]) ? h($_POST['url'][$i]) : '';
	$updated = time();

	//检验必要参数
	if( $id < 1 || $title=='' || $url =='' ){
		continue;
	}

	//组装news的insert数组
	$data=array('title'=>$title,
				'orders'=>$orders,
				'url'=>$url,
				'updated'=>$updated,
				);
	$db->table('relative_news')->where('id='.$id)->update($data)->run();
	
	$id_string .= $id.',';
}
$id_string = substr($id_string, 0, -1);

//记录动作日志
Log::logs_articles(-2, 12, $id_string);

$error_title = '编辑成功 - 编辑推荐文章';
$error_content = '编辑成功！';
$error_pre_button = '<a href="/www/admin/news/news_relative.php" style="margin-right:20px;" id="pre_button">〈〈 返回列表</a>';
$error_next_button = '';
require template('admin/news/news_error');
exit;